#include <iostream>
#include <queue>
#define int long long
using namespace std;
signed main() {
    int n;
    cin >> n;
    priority_queue<int, vector<int>, greater<int>> heap;
    while(n--) {
        int x;
        cin >> x;
        heap.push(x);
    }
    int ans = 0;
    while(heap.size() != 1) {
        int a = heap.top();
        heap.pop();
        int b = heap.top();
        heap.pop();
        heap.push(a + b);
        ans += (a + b);
    }
    cout << ans << endl;
    return 0;
}